﻿
<link href="/ViewV5/CSS/zj.css" rel="stylesheet" />
<link href="/ViewV5/CSS/saved_resource(2).css" rel="stylesheet" />
<script type="text/javascript">
    tempindex = avalon.define({
        $id: "SJGLADD",
        modelData: { "SJName": "", "TotalRecord": "100", "SJDescribe": "", "PassRecord": "60", "KSSC": "", "kcId": ComFunJS.getQueryString("kcId", "0") },
        numberData: ["一", "二", "三", "四", "五", "六", "七", "八"],
        showIndex: 0,
        curTotalST: 0,
        curTotalChildrenST: 0,
        curTotalRecord: 0,
        SaveForm: function () {
            if (!tempindex.modelData.SJName) {
                top.ComFunJS.winwarning("请输入试卷标题");
                return;
            }
            if (!tempindex.modelData.SJDescribe) {
                top.ComFunJS.winwarning("请输入试卷说明");
                return;
            }
            if (!tempindex.modelData.TotalRecord) {
                top.ComFunJS.winwarning("请输入试卷总分");
                return;
            }
            if (!tempindex.modelData.PassRecord) {
                top.ComFunJS.winwarning("请输入试卷及格分");
                return;
            }
            if (!tempindex.modelData.KSSC) {
                top.ComFunJS.winwarning("请输入考试时长");
                return;
            }
            $.post("/API/VIEWAPI.ashx?ACTION=KSGL_ADDSJGL", { P1: JSON.stringify(tempindex.modelData.$model) }, function (result) {
                result = JSON.parse(result);
                if (result.ErrorMsg == "") {
                    tempindex.modelData = result.Result;
                    tempindex.showIndex = 1;
                    tempindex.GetSTTYPELIST();
                } else {
                    top.ComFunJS.winwarning(result.ErrorMsg);
                }

            });

        }, SelSJ: function (item) {
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/KSGL/SELSTLIST.html?type=" + escape(item.TypeName) + "&sjID=" + tempindex.modelData.ID, "选择试题", 1000, 600, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var nowwin = ComFunJS.isIE() ? top.window.frames[frameid] : top.window.frames[frameid].contentWindow;
                var data = nowwin.GetSelSTData();
                if (data.length == 0) {
                    top.ComFunJS.winwarning("请选择试题");
                    return;
                }
                var stIds = "";
                $(data).each(function (i, el) {
                    stIds += el.ID + ",";
                })
                if (stIds) {
                    stIds = stIds.substring(0, stIds.length - 1);
                }
                $.post("/API/VIEWAPI.ashx?ACTION=KSGL_ADDSJST", { P1: tempindex.modelData.ID, P2: stIds, type: item.TypeName }, function (result) {
                    result = JSON.parse(result);
                    if (result.ErrorMsg == "") {
                        item.STCount = data.length;
                        tempindex.curTotalST++;
                        tempindex.curTotalChildrenST += data.length;
                    } else {
                        top.ComFunJS.winwarning(result.ErrorMsg);
                    }

                });
                top.layer.close(index)
            })
        }, STTypeData: [], GetSTTYPELIST: function () {
            tempindex.curTotalRecord = 0;
            tempindex.curTotalChildrenST = 0;
            tempindex.curTotalChildrenST = 0;
            $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETSJTYPELIST', { P1: tempindex.modelData.ID, P2: tempindex.modelData.kcId == 0 ? "" : tempindex.modelData.kcId }, function (result) {
                if (result.ErrorMsg == "") {

                    tempindex.STTypeData = result.Result;
                    tempindex.STTypeData.forEach(function (item) {
                        if (item.STCount) {
                            tempindex.curTotalST++;
                            tempindex.curTotalChildrenST += item.STCount;
                            tempindex.curTotalRecord += item.TotalRecord;
                        }
                    })
                }
            })
        }, InitWigetData: function (data) {
            if (data.sjId) {
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETSJGLMODEL', { P1: data.sjId, P2: data.kcId }, function (result) {
                    if (result.ErrorMsg == "") {
                        if (result.Result) {
                            tempindex.modelData = result.Result;
                        }
                    }
                })
            }
        }, YLSTLSIT: function () {
            top.ComFunJS.winviewform("/ViewV5/AppPage/KSGL/SJGLView.html?sjid=" + tempindex.modelData.ID, "试卷预览", "1000", "");
        }, DFView: function (item) {
            if (item.STCount == 0) {
                top.ComFunJS.winwarning("此题型未选择试题");
                return;
            }
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/KSGL/SJGLDF.html?sjid=" + tempindex.modelData.ID + "&&sjtype=" + escape(item.TypeName), "试卷打分", 1000, 600, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var data = top.window.frames[frameid].GetSTRecordData();
                var resultst = "", msg = "";
                $(data).each(function (i, item) {
                    if (item.Record) {
                        resultst += item.ID + ":" + item.Record + ",";
                    }
                    else {
                        msg += (i + 1) + ",";
                    }
                })
                resultst = resultst.substring(0, resultst.length - 1);
                if (msg) {
                    top.ComFunJS.winwarning("请给第" + msg.substring(0, msg.length - 1) + "题设置分数");
                    return;
                }
                $.post("/API/VIEWAPI.ashx?ACTION=KSGL_ADDSJRECORD", { P1: resultst }, function (result) {
                    result = JSON.parse(result);
                    if (result.ErrorMsg == "") {
                        tempindex.GetSTTYPELIST();
                    }
                });
                top.layer.close(index)
            })
        }, LOOKSTView: function (type) {
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/KSGL/SJGLDF.html?yl=1&&sjid=" + tempindex.modelData.ID + "&&sjtype=" + escape(type), "显示试题", 1000, 600, {}, function (layero, index) {
                top.layer.close(index)
            })
        }, curSTType: "", autoRecord: 0, OpenAutoDF: function (item) {
            if (item.STCount == 0) {
                top.ComFunJS.winwarning("此题型未选择试题");
                return;
            }
            tempindex.curSTType = item.TypeName;
            $("#AUTODFModal").modal("show");
        }, AutoDF: function () {
            if (!tempindex.autoRecord) {
                top.ComFunJS.winwarning("请输入每题分数");
                return;
            }
            $.post("/API/VIEWAPI.ashx?ACTION=KSGL_SJAUTODF", { P1: tempindex.modelData.ID, P2: tempindex.curSTType, record: tempindex.autoRecord }, function (result) {
                result = JSON.parse(result);
                if (result.ErrorMsg == "") {
                    top.ComFunJS.winsuccess("分数添加成功");
                    tempindex.GetSTTYPELIST();
                    $("#AUTODFModal").modal("hide");
                }
            });
        }, KSRELEASE: function (type) {
            if (type == 1) {
                top.ComFunJS.winsuccess("保存成功");
                model.refpage();
                return;
            }
            if (type == 2) {
                tempindex.STTypeData.forEach(function (item) {
                    if (item.STCount > 0 && item.TotalRecord == 0) {
                        top.ComFunJS.winwarning(item.TypeName + "分数为空");
                        return;
                    }
                })
                top.ComFunJS.winconfirm("发布后试卷信息将不能更改，确定要发布吗？", function () {
                    $.getJSON("/API/VIEWAPI.ashx?ACTION=KSGL_KSRELEASE", { P1: tempindex.modelData.ID }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            top.ComFunJS.winsuccess("发布成功");
                            model.refpage();
                        }
                        else {
                            top.ComFunJS.winwarning(resultData.ErrorMsg);
                        }
                    });
                })
            }
        }
    }) //@ sourceURL=SJGL.js;
</script>
<div ms-controller="SJGLADD">
    <div class="set-volume" style="margin-top:5px;">
        <div class="set-tab">
            <ul class="tab-first clearfix">
                <li ms-class="active:showIndex==0" style="width:50%">
                    <span>1</span>
                    填写试卷信息
                </li>
                <li ms-class="active:showIndex==1" style="width:50%">
                    <span>2</span>
                    选择试题
                </li>
            </ul>
        </div>
        <!-- 填写试卷信息 -->
        <div class="set-box1" ms-if="showIndex==0">
            <form class="form-horizontal" role="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label">试卷标题</label>
                    <div class="col-sm-6">
                        <input class="form-control" ms-duplex="modelData.SJName" id="focusedInput" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">试卷说明</label>
                    <div class="col-sm-6">
                        <input class="form-control" ms-duplex="modelData.SJDescribe" id="focusedInput" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">试卷总分</label>
                    <div class="col-sm-6">
                        <input class="form-control" ms-duplex="modelData.TotalRecord" id="focusedInput" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">及格分</label>
                    <div class="col-sm-6">
                        <input class="form-control" ms-duplex="modelData.PassRecord" id="focusedInput" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">考试时间(分钟)</label>
                    <div class="col-sm-6">
                        <input class="form-control" ms-duplex="modelData.KSSC" id="focusedInput" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-6" style="text-align:center">
                        <button type="button" class="btn  btn-primary next1 btn-all" style="padding:5px 30px" ms-click="SaveForm()">下一步</button>
                    </div>
                </div>

            </form>
        </div>
        <!-- 选择试题 -->
        <div class="set-box2 color-666" ms-if="showIndex==1">
            <div class="m-examHead">
                <!--试卷头信息-->
                <h1 class="h1"> {{modelData.SJName}} </h1>
                <div class="info">
                    <p class="tc">◇ 本卷共分为 {{curTotalST}}大题 {{curTotalChildrenST}}小题，作答时间为 {{modelData.KSSC}}分钟，总分 {{modelData.TotalRecord}} 分，{{modelData.PassRecord}} 分及格。</p>
                    <p class="tc" style="color:red;font-size:14px;">◇ 现有题总分：{{curTotalRecord}}分</p>
                </div>
            </div>
            <!-- 1 -->
            <div class="score-list" ms-repeat-item="STTypeData">

                <div class="ui-progress f-shadow">
                    <div class="m-secpart">
                        {{numberData[$index]}}、{{item.TypeName}}
                        <div class="score-fun">
                            <div class="di item-list">
                                <a class="" ms-click="LOOKSTView(item.TypeName)">显示试题</a>
                            </div>
                            <div class="di item-list">
                                已选<span class="important-cor">{{item.STCount}}</span>题
                            </div>
                            <div class="di item-list">
                                共<span class="important-cor">{{item.TotalRecord}}</span>分
                            </div>
                            <div class="di item-list xt-btn-box">
                                <a class="xt-btn" style="float:left" ms-click="SelSJ(item)">选题</a>
                                <div class="btn-group" role="group" style="float:left;margin-left:10px">
                                    <button type="button" class="btn btn-default" ms-click="OpenAutoDF(item)">批量设置分数</button>
                                    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                        <span class="sr-only">Toggle Dropdown</span>
                                    </button>
                                    <ul class="dropdown-menu">
                                        <li ms-click="DFView(item)"><a>单独设置分数</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="text-align:center;margin-bottom:20px;">
                <button type="button" class="btn btn-large btn-primary" style="width:100px;" ms-click="KSRELEASE(1)" ms-if="modelData.Status==0"> 保 存 </button>
                <button type="button" class="btn btn-large btn-primary" style="width:100px;" ms-click="KSRELEASE(2)" ms-if="modelData.Status==0"> 保存并发布 </button>
                <button type="button" class="btn btn-large  btn-info" style="width:100px;" ms-click="YLSTLSIT()"> 预 览 </button>
            </div>
        </div>
        <!--预览-->

    </div>
    <div class="modal fade" id="AUTODFModal" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">批量设置分数</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">每题分数</label>
                            <input type="text" class="form-control" style="width: 200px" ms-duplex="autoRecord" placeholder="请输入分数" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="AutoDF(this)">确&nbsp;&nbsp;认</button>
                </div>
            </div>
        </div>
    </div>
</div>